#include "lcd_init.h"
#include "stdio.h"
#include <string.h>
// #include "app.h"

typedef void (*FunType)(void);
//**********************************write function begin********************************************
void wr_cmd_4spi_8bcs(uint8_t par)
{
    LCD_DCXLow();
    LCD_CSLow();

    LCD_SCLLow();
    if (par & 0x80)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x40)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x20)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x10)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x08)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x04)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x02)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x01)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_CSHigh();
    LCD_DCXHigh();
    HAL_Delay(5);
}
void wr_dat_4spi_8bcs(uint8_t par)
{
    LCD_DCXHigh();
    LCD_CSLow();

    LCD_SCLLow();
    if (par & 0x80)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x40)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x20)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x10)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x08)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x04)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x02)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_SCLLow();
    if (par & 0x01)
        LCD_SDAHigh();
    else
        LCD_SDALow();
    LCD_SCLHigh();

    LCD_CSHigh();
    LCD_DCXHigh();
    HAL_Delay(1);
}
void wr_cmd_parall1_8(uint16_t par)
{
    LCD_DCXLow();
    LCD_CSLow();
    LCD_WRLow();
    GPIOB->ODR = par;

    LCD_WRHigh();
}
void wr_dat_parall1_8(uint16_t par)
{
    LCD_DCXHigh();
    LCD_WRLow();
    GPIOB->ODR = par;

    LCD_WRHigh();
}
void wr_cmd_parall2_8(uint16_t par)
{
    LCD_DCXLow();
    LCD_CSLow();
    LCD_WRLow();
    GPIOB->ODR = par << 1;

    LCD_WRHigh();
}
void wr_dat_parall2_8(uint16_t par)
{
    LCD_DCXHigh();
    LCD_WRLow();
    GPIOB->ODR = par << 1;

    LCD_WRHigh();
}

void wr_cmd_3spi_9bit(uint8_t par)
{
    LCD_CSLow();
    LCD_SCLLow();
    LCD_SDALow();
    LCD_SCLHigh();

    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (par & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        par = par << 1;
        LCD_SCLHigh();
    }
    LCD_CSHigh();
}

void wr_dat_3spi_9bit(uint8_t par)
{
    LCD_CSLow();
    LCD_SCLLow();
    LCD_SDAHigh();
    LCD_SCLHigh();

    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (par & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        par = par << 1;
        LCD_SCLHigh();
    }
    LCD_CSHigh();
}

void LCD_WR_REG(uint8_t par)
{
    LCD_SCLLow();
    LCD_DCXLow();
    LCD_CSLow();

    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (par & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        par = par << 1;
        LCD_SCLHigh();
    }
    LCD_CSHigh();
}

void LCD_WR_DATAX(uint8_t par)
{
    LCD_SCLLow();
    LCD_DCXHigh();
    LCD_CSLow();

    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (par & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        par = par << 1;
        LCD_SCLHigh();
    }
    LCD_CSHigh();
}
//**********************************read function begin********************************************
void sda_state(uint8_t state)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};
    if (state == 0)
    {
        GPIO_InitStruct.Pin = SPI1_MOSI_Pin;
        GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    }
    else if (state == 1)
    {
        GPIO_InitStruct.Pin = SPI1_MOSI_Pin;
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
    }
}
uint32_t read_reg(uint8_t reg)
{
    uint32_t re_val = 0;
    uint16_t addr = reg;
    uint16_t id1, id2, id3 = 0;
    sda_state(io_writ);
    // LCD_SCLLow();
    LCD_DCXLow();
    LCD_CSLow();
    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (reg & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        reg = reg << 1;
        LCD_SCLHigh();
    }
    LCD_DCXHigh();
    sda_state(io_read);
    for (uint8_t i = 0; i < 24; i++)
    {
        LCD_SCLLow();
        re_val = re_val << 1;
        re_val = re_val + HAL_GPIO_ReadPin(SPI1_MOSI_GPIO_Port, SPI1_MOSI_Pin);
        LCD_SCLHigh();
    }
    LCD_CSHigh();
    LCD_SCLLow();

    sda_state(io_writ);
    id1 = (re_val >> 16) & 0xFF;
    id2 = (re_val >> 8) & 0xFF;
    id3 = (re_val) & 0xFF;

    printf("reg 0x%02x data is\n\r%02x\n\r%02x\n\r%02x\n\r", addr, id1, id2, id3);

    return re_val;
}

uint16_t read_one(uint8_t reg)
{
    uint16_t re_val = 0;
    uint16_t addr = reg;
    sda_state(io_writ);
    // LCD_SCLLow();
    LCD_DCXLow();
    LCD_CSLow();
    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        if (reg & 0x80)
        {
            LCD_SDAHigh();
        }
        else
        {
            LCD_SDALow();
        }
        reg = reg << 1;
        LCD_SCLHigh();
    }
    LCD_DCXHigh();
    sda_state(io_read);
    for (uint8_t i = 0; i < 8; i++)
    {
        LCD_SCLLow();
        re_val = re_val << 1;
        re_val = re_val + HAL_GPIO_ReadPin(SPI1_MOSI_GPIO_Port, SPI1_MOSI_Pin);
        LCD_SCLHigh();
    }
    LCD_CSHigh();
    LCD_SCLLow();

    printf("reg %02x one data is %02x\n\r", addr, re_val);

    sda_state(io_writ);

    return re_val;
}

void pb_out(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    // db 0-7
    GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
                          GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
void pb_in(void)
{
    GPIO_InitTypeDef GPIO_InitStruct = {0};

    // db 0-7
    GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 |
                          GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7;
    GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
uint8_t i801_read_byte(void)
{
    uint8_t v;

    LCD_DCXHigh();
    LCD_RDLow();
    v = GPIOB->IDR;
    LCD_RDHigh();

    return v;
}
void rd_parall1_8(uint8_t c, uint8_t *d, uint32_t l)
{
    uint8_t buf[128];

    wr_cmd_parall1_8(c);
    pb_in();
    for (int i = 0; i < l; i++)
    {
        buf[i] = i801_read_byte();
    }
    LCD_CSHigh();
    pb_out();
    memcpy(d, buf, l);
}
//**********************************write display begin********************************************
void wr_displ_parall1_8(uint8_t color)
{
    LCD_DCXHigh();
    LCD_WRLow();
    GPIOB->ODR = color;
    LCD_WRHigh();
}
void wr_displ_parall2_18(uint16_t color1, uint16_t color2)
{
    LCD_DCXHigh();
    LCD_WRLow();
    if (color1 & 0x02)
        HAL_GPIO_WritePin(DB17_GPIO_Port, DB17_Pin, GPIO_PIN_SET);
    else
        HAL_GPIO_WritePin(DB17_GPIO_Port, DB17_Pin, GPIO_PIN_RESET);
    if (color1 & 0x01)
        HAL_GPIO_WritePin(DB16_GPIO_Port, DB16_Pin, GPIO_PIN_SET);
    else
        HAL_GPIO_WritePin(DB16_GPIO_Port, DB16_Pin, GPIO_PIN_RESET);
    GPIOB->ODR = color2;
    LCD_WRHigh();
}
// #endif
void C096LAB_Init(void)
{
    LCD_RSTHigh();
    HAL_Delay(120);
    LCD_RSTLow();
    HAL_Delay(120);
    LCD_RSTHigh();
    HAL_Delay(200);

    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x00);

    //read_reg(0x04);
    //read_one(0x56);
    //LCD_WR_REG(0x10);
    //printf("set 0x10\n\r");
    //read_reg(0X09);
    //read_one(0X0A);
    //LCD_WR_REG(0x11);
    //printf("set 0x11\n\r");
    //HAL_Delay(200);
    //read_reg(0X09);
    //read_one(0X0A);
    //LCD_WR_REG(0x28);
    //printf("set 0x28\n\r");
    //read_reg(0X09);
    //read_one(0X0A);
    //LCD_WR_REG(0x29);
    //printf("set 0x29\n\r");
    //read_reg(0X09);
    //read_one(0X0A);

    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x43);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0x04);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x10);
    LCD_WR_REG(0x62);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x61);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x5C);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x58);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x55);
    LCD_WR_DATAX(0x55);
    LCD_WR_REG(0x54);
    LCD_WR_DATAX(0x44);
    LCD_WR_REG(0x51);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x4B);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x4A);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x49);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x47);
    LCD_WR_DATAX(0x77);
    LCD_WR_REG(0x46);
    LCD_WR_DATAX(0x66);
    LCD_WR_REG(0x45);
    LCD_WR_DATAX(0x55);
    LCD_WR_REG(0x44);
    LCD_WR_DATAX(0x44);
    LCD_WR_REG(0x43);
    LCD_WR_DATAX(0x33);
    LCD_WR_REG(0x42);
    LCD_WR_DATAX(0x22);
    LCD_WR_REG(0x41);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x37);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x36);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x35);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x34);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x33);
    LCD_WR_DATAX(0x20);
    LCD_WR_REG(0x32);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x31);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x30);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x27);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x26);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x25);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x24);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x23);
    LCD_WR_DATAX(0x20);
    LCD_WR_REG(0x22);
    LCD_WR_DATAX(0x72);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x82);
    LCD_WR_REG(0x20);
    LCD_WR_DATAX(0x81);
    LCD_WR_REG(0x1B);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x1A);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x16);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x15);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x11);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x10);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x0C);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x0B);
    LCD_WR_DATAX(0x43);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x11);
    LCD_WR_REG(0x6A);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x69);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x68);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x67);
    LCD_WR_DATAX(0x04);
    LCD_WR_REG(0x66);
    LCD_WR_DATAX(0x38);
    LCD_WR_REG(0x65);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x64);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x63);
    LCD_WR_DATAX(0x04);
    LCD_WR_REG(0x62);
    LCD_WR_DATAX(0x38);
    LCD_WR_REG(0x61);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x60);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x55);
    LCD_WR_DATAX(0x06);
    LCD_WR_REG(0x50);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x30);
    LCD_WR_DATAX(0x11); // EE 0E 00
    LCD_WR_REG(0x1E);
    LCD_WR_DATAX(0x88);
    LCD_WR_REG(0x1D);
    LCD_WR_DATAX(0x88);
    LCD_WR_REG(0x1C);
    LCD_WR_DATAX(0x88);
    LCD_WR_REG(0x16);
    LCD_WR_DATAX(0x99);
    LCD_WR_REG(0x15);
    LCD_WR_DATAX(0x99);
    LCD_WR_REG(0x14);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x13);
    LCD_WR_DATAX(0xf0);
    LCD_WR_REG(0x0c);
    LCD_WR_DATAX(0xde);
    LCD_WR_REG(0x0B);
    LCD_WR_DATAX(0xde);
    LCD_WR_REG(0x0A);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x09);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0x60);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x2E);
    LCD_WR_DATAX(0x1e);
    LCD_WR_REG(0x2D);
    LCD_WR_DATAX(0x28);
    LCD_WR_REG(0x2C);
    LCD_WR_DATAX(0x26);
    LCD_WR_REG(0x2B);
    LCD_WR_DATAX(0x1e);
    LCD_WR_REG(0x2A);
    LCD_WR_DATAX(0x28);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x52); // VCOM
    LCD_WR_REG(0x1F);
    LCD_WR_DATAX(0xDC);
    LCD_WR_REG(0x15);
    LCD_WR_DATAX(0x0F);
    LCD_WR_REG(0x12);
    LCD_WR_DATAX(0x89);
    LCD_WR_REG(0x10);
    LCD_WR_DATAX(0x0F);
    LCD_WR_REG(0x0D);
    LCD_WR_DATAX(0x66);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x06);
    LCD_WR_REG(0x00);
    LCD_WR_DATAX(0x99);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x15);
    LCD_WR_REG(0x2F);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x2E);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x2D);
    LCD_WR_DATAX(0x35);
    LCD_WR_REG(0x2C);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x2B);
    LCD_WR_DATAX(0x32);
    LCD_WR_REG(0x2A);
    LCD_WR_DATAX(0x33);
    LCD_WR_REG(0x29);
    LCD_WR_DATAX(0x19);
    LCD_WR_REG(0x28);
    LCD_WR_DATAX(0x17);
    LCD_WR_REG(0x27);
    LCD_WR_DATAX(0x1D);
    LCD_WR_REG(0x26);
    LCD_WR_DATAX(0x1B);
    LCD_WR_REG(0x25);
    LCD_WR_DATAX(0x09);
    LCD_WR_REG(0x24);
    LCD_WR_DATAX(0x05);
    LCD_WR_REG(0x23);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x22);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x20);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0F);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x0E);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x0D);
    LCD_WR_DATAX(0x35);
    LCD_WR_REG(0x0C);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x0B);
    LCD_WR_DATAX(0x32);
    LCD_WR_REG(0x0A);
    LCD_WR_DATAX(0x33);
    LCD_WR_REG(0x09);
    LCD_WR_DATAX(0x16);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0x18);
    LCD_WR_REG(0x07);
    LCD_WR_DATAX(0x1A);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x1C);
    LCD_WR_REG(0x05);
    LCD_WR_DATAX(0x04);
    LCD_WR_REG(0x04);
    LCD_WR_DATAX(0x08);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x01);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x00);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x16);
    LCD_WR_REG(0x2F);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x2E);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x2D);
    LCD_WR_DATAX(0x35);
    LCD_WR_REG(0x2C);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x2B);
    LCD_WR_DATAX(0x32);
    LCD_WR_REG(0x2A);
    LCD_WR_DATAX(0x33);
    LCD_WR_REG(0x29);
    LCD_WR_DATAX(0x18);
    LCD_WR_REG(0x28);
    LCD_WR_DATAX(0x16);
    LCD_WR_REG(0x27);
    LCD_WR_DATAX(0x1C);
    LCD_WR_REG(0x26);
    LCD_WR_DATAX(0x1A);
    LCD_WR_REG(0x25);
    LCD_WR_DATAX(0x08);
    LCD_WR_REG(0x24);
    LCD_WR_DATAX(0x04);
    LCD_WR_REG(0x23);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x22);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x20);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0F);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x0E);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x0D);
    LCD_WR_DATAX(0x35);
    LCD_WR_REG(0x0C);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x0B);
    LCD_WR_DATAX(0x32);
    LCD_WR_REG(0x0A);
    LCD_WR_DATAX(0x33);
    LCD_WR_REG(0x09);
    LCD_WR_DATAX(0x17);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0x19);
    LCD_WR_REG(0x07);
    LCD_WR_DATAX(0x1B);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x1D);
    LCD_WR_REG(0x05);
    LCD_WR_DATAX(0x05);
    LCD_WR_REG(0x04);
    LCD_WR_DATAX(0x09);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x01);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x00);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x17);
    LCD_WR_REG(0x39);
    LCD_WR_DATAX(0x3c);
    LCD_WR_REG(0x37);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x1F);
    LCD_WR_DATAX(0x80);
    LCD_WR_REG(0x1A);
    LCD_WR_DATAX(0x80);
    LCD_WR_REG(0x18);
    LCD_WR_DATAX(0xA0);
    LCD_WR_REG(0x16);
    LCD_WR_DATAX(0x12);
    LCD_WR_REG(0x14);
    LCD_WR_DATAX(0xAA);
    LCD_WR_REG(0x11);
    LCD_WR_DATAX(0xAA);
    LCD_WR_REG(0x10);
    LCD_WR_DATAX(0x0E);
    LCD_WR_REG(0x0B);
    LCD_WR_DATAX(0xC3);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x18);
    LCD_WR_REG(0x3A);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x1F);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x01);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x00);
    LCD_WR_DATAX(0x1E);
    LCD_WR_REG(0xff);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x2D);
    LCD_WR_REG(0x01);
    LCD_WR_DATAX(0x3E);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0xff);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x31);
    LCD_WR_REG(0x39);
    LCD_WR_DATAX(0xf0);
    LCD_WR_REG(0x38);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x37);
    LCD_WR_DATAX(0xe8);
    LCD_WR_REG(0x36);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x35);
    LCD_WR_DATAX(0xCF);
    LCD_WR_REG(0x34);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x33);
    LCD_WR_DATAX(0xBA);
    LCD_WR_REG(0x32);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x31);
    LCD_WR_DATAX(0xA2);
    LCD_WR_REG(0x30);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2f);
    LCD_WR_DATAX(0x8E);
    LCD_WR_REG(0x2e);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2d);
    LCD_WR_DATAX(0x7e);
    LCD_WR_REG(0x2c);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2b);
    LCD_WR_DATAX(0x62);
    LCD_WR_REG(0x2a);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x29);
    LCD_WR_DATAX(0x38);
    LCD_WR_REG(0x28);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x27);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x26);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x25);
    LCD_WR_DATAX(0xd8);
    LCD_WR_REG(0x24);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x23);
    LCD_WR_DATAX(0xa2);
    LCD_WR_REG(0x22);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x78);
    LCD_WR_REG(0x20);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x1f);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x1e);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x1d);
    LCD_WR_DATAX(0xfa);
    LCD_WR_REG(0x1c);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x1b);
    LCD_WR_DATAX(0xbb);
    LCD_WR_REG(0x1a);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x19);
    LCD_WR_DATAX(0x70);
    LCD_WR_REG(0x18);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x17);
    LCD_WR_DATAX(0x3e);
    LCD_WR_REG(0x16);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x15);
    LCD_WR_DATAX(0xf4);
    LCD_WR_REG(0x14);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x13);
    LCD_WR_DATAX(0xd0);
    LCD_WR_REG(0x12);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x11);
    LCD_WR_DATAX(0xa0);
    LCD_WR_REG(0x10);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0f);
    LCD_WR_DATAX(0x90);
    LCD_WR_REG(0x0e);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0d);
    LCD_WR_DATAX(0x7c);
    LCD_WR_REG(0x0c);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0b);
    LCD_WR_DATAX(0x6a);
    LCD_WR_REG(0x0a);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x09);
    LCD_WR_DATAX(0x58);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x07);
    LCD_WR_DATAX(0x4c);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x05);
    LCD_WR_DATAX(0x2f);
    LCD_WR_REG(0x04);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0x14);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0xff);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x32);
    LCD_WR_REG(0x39);
    LCD_WR_DATAX(0xf0);
    LCD_WR_REG(0x38);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x37);
    LCD_WR_DATAX(0xe8);
    LCD_WR_REG(0x36);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x35);
    LCD_WR_DATAX(0xCF);
    LCD_WR_REG(0x34);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x33);
    LCD_WR_DATAX(0xBA);
    LCD_WR_REG(0x32);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x31);
    LCD_WR_DATAX(0xA2);
    LCD_WR_REG(0x30);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2f);
    LCD_WR_DATAX(0x8E);
    LCD_WR_REG(0x2e);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2d);
    LCD_WR_DATAX(0x7E);
    LCD_WR_REG(0x2c);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x2b);
    LCD_WR_DATAX(0x62);
    LCD_WR_REG(0x2a);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x29);
    LCD_WR_DATAX(0x38);
    LCD_WR_REG(0x28);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x27);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x26);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x25);
    LCD_WR_DATAX(0xd8);
    LCD_WR_REG(0x24);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x23);
    LCD_WR_DATAX(0xa2);
    LCD_WR_REG(0x22);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x21);
    LCD_WR_DATAX(0x78);
    LCD_WR_REG(0x20);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x1f);
    LCD_WR_DATAX(0x34);
    LCD_WR_REG(0x1e);
    LCD_WR_DATAX(0x02);
    LCD_WR_REG(0x1d);
    LCD_WR_DATAX(0xfa);
    LCD_WR_REG(0x1c);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x1b);
    LCD_WR_DATAX(0xbb);
    LCD_WR_REG(0x1a);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x19);
    LCD_WR_DATAX(0x70);
    LCD_WR_REG(0x18);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x17);
    LCD_WR_DATAX(0x3e);
    LCD_WR_REG(0x16);
    LCD_WR_DATAX(0x01);
    LCD_WR_REG(0x15);
    LCD_WR_DATAX(0xf4);
    LCD_WR_REG(0x14);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x13);
    LCD_WR_DATAX(0xd0);
    LCD_WR_REG(0x12);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x11);
    LCD_WR_DATAX(0xa0);
    LCD_WR_REG(0x10);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0f);
    LCD_WR_DATAX(0x90);
    LCD_WR_REG(0x0e);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0d);
    LCD_WR_DATAX(0x7c);
    LCD_WR_REG(0x0c);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x0b);
    LCD_WR_DATAX(0x6a);
    LCD_WR_REG(0x0a);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x09);
    LCD_WR_DATAX(0x58);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x07);
    LCD_WR_DATAX(0x4c);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x05);
    LCD_WR_DATAX(0x2F);
    LCD_WR_REG(0x04);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0x14);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0xff);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x40);
    LCD_WR_REG(0x86);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x83);
    LCD_WR_DATAX(0xC4);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x42);
    LCD_WR_REG(0x06);
    LCD_WR_DATAX(0x03);
    LCD_WR_REG(0x05);
    LCD_WR_DATAX(0x3D);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x45);
    LCD_WR_REG(0x03);
    LCD_WR_DATAX(0xB4);
    LCD_WR_REG(0x02);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x01);
    LCD_WR_DATAX(0xC6);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0xA0);
    LCD_WR_REG(0x08);
    LCD_WR_DATAX(0xdc);
    LCD_WR_REG(0xFF);
    LCD_WR_DATAX(0x20);
    LCD_WR_DATAX(0x10);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x2A);
    LCD_WR_DATAX(0x00);
    LCD_WR_DATAX(0x00);
    LCD_WR_DATAX(0x00);
    LCD_WR_DATAX(0xB3);
    LCD_WR_REG(0x2B);
    LCD_WR_DATAX(0x00);
    LCD_WR_DATAX(0x00);
    LCD_WR_DATAX(0x01);
    LCD_WR_DATAX(0xC5);
    LCD_WR_REG(0x3A);
    LCD_WR_DATAX(0x06); // RGB16 位 ,0x07=RGB24 位, 0x06=RGB18 位
    LCD_WR_REG(0x35);
    LCD_WR_DATAX(0x00);
    LCD_WR_REG(0x11);
    HAL_Delay(100);
    LCD_WR_REG(0x29);
    HAL_Delay(100);

    // wr_cmd_3spi_9bit(0x1C);
}
